/**
 * @Author: zhongyang
 * @Date: 2022/6/21 15:07
 */

package main

import "fmt"

type Animal interface {
	eat()
}

type Monkey struct {
}

type Bird struct {
}

func (b Bird) eat() {
	fmt.Println("小鸟吃饭")
}

func (m Monkey) eat() {
	fmt.Println("猴子吃饭")
}

func getAnimal(typeName string) Animal {
	switch typeName {
	case "monkey":
		animal := new(Monkey)
		return animal
	case "bird":
		animal := new(Bird)
		return animal
	}
	return nil
}

func main() {
	// 获取小鸟
	animal := getAnimal("bird")
	animal.eat()

	// 获取猴子
	animal = getAnimal("monkey")
	animal.eat()
}
